from mtp.lib.base import *
from mtp.lib.plugin import Plugin 


class UserManagerController(BaseController):
    def index(self):
        c.users = model.User.getAll()
        c.groups = model.Group.getAll()
        return render('/usrmgr/index.html')
            

class UserController(BaseController):
    def show(self, id):
        c.user = model.User.getByUsername(id)
        return render('/usrmgr/user_show.html')


class GroupController(BaseController):
    pass


class UserManagerPlugin(Plugin):
    def __init__(self, **options):  
        config['mtp.controllers']['usermgr'] = UserManagerController
        config['mtp.controllers']['usermgruser'] = UserController
        config['mtp.controllers']['usermgrgroup'] = GroupController

        map = config['mtp.map']
        map.configConnect('usermgr', 'usermgr', 
            controller='usermgr', action='index')
        map.configResource('user', 'users', 
            path_prefix="usermgr/", name_prefix="usermgr_", controller='usermgruser')
        map.configResource('group', 'groups', 
            path_prefix="usermgr/", name_prefix="usermgr_", controller='usermgrgroup')

        config['mtp.config_links']['User Manager'] = (
            h.url_for('usermgr'),
            "Manage users and groups"
        )
    


